<template>
	<view class="page" :style="themeColor">
		<view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex payImmediately_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between payImmediately_fd0_0'>
				<view class='flex flex-wrap align-center payImmediately_fd0_0_c0' @tap.stop="handleJumpDiy"
					data-type="back" data-url="1">
					<text class='fu-iconfont2  payImmediately_fd0_0_c0_c0'>&#xE794;</text>
				</view>
				<view class='flex flex-wrap align-center'>
					<text class='payImmediately_fd0_0_c1_c0'>立即支付</text>
				</view>
				<view class='flex align-center justify-end payImmediately_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<!---flex布局flex布局开始-->
		<view class="flex flex-direction flex-wrap align-center benben-flex-layout payImmediately_flex_1">
			<view class='flex flex-wrap align-center'>
				<text class='payImmediately_fd1_0_c0'>￥</text>
				<view class=' payImmediately_fd1_0_c1'>
					<text class=' payImmediately_price1_fd1_0_c1'>{{ money | frontPrice }}</text>
					<text class=' payImmediately_price2_fd1_0_c1'>{{ money | laterPrice }}</text>
				</view>
			</view>
			<view class='flex flex-wrap align-center payImmediately_fd1_1'>
				<text class='payImmediately_fd1_1_c0'>支付剩余时间：</text>
				<benben-countdown class='payImmediately_fd1_1_c1' :time-type='false' :countTime="time"
					@timeEnd="toBackFunc()">
					<template #default="{ d, h, i, s }">
						<text>{{h}}</text>

						<text>:</text>

						<text>{{i}}</text>

						<text>:</text>

						<text>{{s}}</text>

						<text></text>
					</template>
				</benben-countdown>
			</view>
		</view>
		<!---flex布局flex布局结束-->
		<!---提现账户flex布局开始-->
		<view class="flex flex-direction flex-wrap align-stretch payImmediately_flex_2">
			<view class='flex flex-wrap align-center justify-between payImmediately_fd2_0'>
				<text class='payImmediately_fd2_0_c0'>选择支付方式</text>
			</view>
			<benben-select-diy ref="showSelectPopup1657185009849" class-name='flex flex-direction align-stretch flex'
				:items.sync="select_Pay" v-model="select_Id" default-type="value" default-label="name"
				:allow-cancel='true' type="radio" :disabled='false'>
				<template v-for='(item,key0) in select_Pay'>
					<view v-if="item.isSelected" class='flex align-center flex payImmediately_fd2_1_c0' :key="key0"
						@tap="$refs.showSelectPopup1657185009849.tapHandle(key0)">
						<image class='payImmediately_fd2_1_c0_c0' mode="aspectFit" :src='item.image'></image>
						<text class='flex-sub payImmediately_fd2_1_c0_c1'>{{item.name}}</text>
						<image class='payImmediately_fd2_1_c0_c2' mode="aspectFit" :src='STATIC_URL+"33.png"'></image>
					</view>
					<view v-else class='flex align-center flex payImmediately_fd2_1_c1' :key="key0"
						@tap="$refs.showSelectPopup1657185009849.tapHandle(key0)">
						<image class='payImmediately_fd2_1_c1_c0' mode="aspectFit" :src='item.image'></image>
						<text class='flex-sub payImmediately_fd2_1_c1_c1'>{{item.name}}</text>
						<image class='payImmediately_fd2_1_c1_c2' mode="aspectFit" :src='STATIC_URL+"81.png"'></image>
					</view>
				</template></benben-select-diy>
		</view>
		<!---提现账户flex布局结束-->
		<view class="flex flex-wrap align-center justify-center benben-position-layout flex payImmediately_flex_3">
			<button class='payImmediately_fd3_0' @tap.stop="payFunc()">立即支付</button>

		</view>
		<view :style="{height: '88rpx'}"></view>


	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				"pay_type": [{
					"name": "微信支付",
					"value": "1",
					"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20220611/c06292acdee3d16014c75eee20f5ac87.png"
				}, {
					"name": "支付宝支付",
					"value": "2",
					"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20220707/23c81a8c5c50ea6fda54ea519396f37f.png"
				}, {
					"name": "余额支付",
					"value": "3",
					"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20220214/d26eaa0eaa4330154437ce31f3af6ffa.png"
				}],
				"pay_id": "1",
				"payInfo": "",
				"select_Pay": [{
					"name": "微信支付",
					"value": "1",
					"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20230412/5e44466352c1cfb3e0a15eb9db337dc1.png"
				}, {
					"name": "支付宝支付",
					"value": "2",
					"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20230412/784b0d8a3adbbe856dbe4db586978b83.png"
				}],
				"select_Id": "1",
				"order_sn": "",
				"money": "0",
				"time": "1",
				"order_type": "1",   // 1购买   2租赁   3 租赁续费
				"loading": false
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {
				order_sn,
				order_type
			} = options
			if (order_sn !== undefined) this.order_sn = order_sn
			if (order_type !== undefined) this.order_type = order_type
			// this.loadPayDataFunc();
			this.getOrderTime();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 获取待支付时间   post643f7314b5f80
			getOrderTime() {
				this.$api.post(global.apiUrls.post643f7314b5f80, {
					order_sn: this.order_sn,
					order_type: this.order_type
				}).then(res => {
					if (res.data.code == 1) {
						this.money = res.data.data.payable_money;
						this.time = res.data.data.pay_time;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			//支付
			payFunc() {
				if (this.loading) return;
				uni.showLoading();
				this.loading = true;
				this.$api.post(global.apiUrls.post643cb2b8ce380, {
					order_sn: this.order_sn,
					order_type: this.order_type == 3 ? 'renew' : 'goods',
					pay_type: this.select_Id == 1 ? 'wxpay' : 'alipay'
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 1) {
						if (this.select_Id == 1) {
							let data = res.data.data;
							uni.requestPayment({
								provider: 'wxpay',
								// #ifdef MP-WEIXIN
								timeStamp: data.timeStamp,
								nonceStr: data.nonceStr,
								package: data.package,
								signType: data.signType,
								paySign: data.paySign,
								// #endif
								// #ifdef APP-PLUS
								orderInfo: data,
								// #endif
								success: (e) => {
									console.log('success', e)
									uni.showToast({
										title: '支付成功',
										icon: 'none'
									})
									global.order_msg_type = 2;
									getApp().orderChat();
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/Cart/paymentResults/paymentResults?order_type=' + this.order_type + '&select_Id=' + this.select_Id
										})
									}, 800)
						
								},
								fail: (e) => {
									console.log('fail', e);
									if (e.errMsg == 'failMsg') {
										uni.showToast({
											title: '取消支付',
											icon: 'none'
										})
									} else {
										uni.showToast({
											title: '支付失败,请稍后重试',
											icon: 'none'
										})
									}
						
								},
								complete: () => {
									this.loading = false;
								}
							});
						} else if (this.select_Id == 2) {
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: res.data.data,
								success: (e) => {
									uni.showToast({
										title: '支付成功',
										icon: 'none'
									})
									global.order_msg_type = 2;
									getApp().orderChat();
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/Cart/paymentResults/paymentResults?order_type=' + this.order_type + '&select_Id=' + this.select_Id
										})
									}, 800)
								},
								fail: (e) => {
									if (e.errMsg == 'requestPayment:fail canceled') {
										uni.showToast({
											title: '取消支付',
											icon: 'none'
										})
									} else {
										uni.showToast({
											title: '支付失败,请稍后重试',
											icon: 'none'
										})
									}
								},
								complete: () => {
									this.loading = false;
								}
							})
						}
						
					} else {
						this.loading = false;
						this.$message.info(res.data.msg);
					}
				})
			},
			//倒计时结束
			toBackFunc() {
				uni.navigateBack({
					delta: 1
				});
			},
			//初始化可调用支付类型
			loadPayDataFunc() {
				this.pay_type = [{
						"name": "微信支付",
						"value": "1",
						"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20220611/c06292acdee3d16014c75eee20f5ac87.png"
					},
					// 兼容微信小程序无法使用其他支付
					// #ifndef MP-WEIXIN
					{
						"name": "支付宝支付",
						"value": "2",
						"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20220707/23c81a8c5c50ea6fda54ea519396f37f.png"
					},
					{
						"name": "余额支付",
						"value": "3",
						"image": "https://zhongben-crm.oss-cn-zhangjiakou.aliyuncs.com/uploads/images/20220214/d26eaa0eaa4330154437ce31f3af6ffa.png"
					},
					// #endif
				]
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(248, 248, 248, 1);
		background-size: 100% auto !important;
	}

	.payImmediately_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.payImmediately_fd0_0_c2 {
		padding: 0rpx 0rpx 0rpx 0rpx;
		width: 200rpx;
	}

	.payImmediately_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
	}

	.payImmediately_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
		font-weight: 500;
	}

	.payImmediately_fd0_0_c0 {
		width: 200rpx;
	}

	.payImmediately_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
	}

	.payImmediately_flex_1 {
		border-bottom: 10px solid rgba(246, 247, 249, 1);
		background: #fff;
		padding: 62rpx 0rpx 56rpx 0rpx;
		background-size: 100% auto !important;
	}

	.payImmediately_fd1_1_c1 {
		background: #FFFFFF;
	}

	.payImmediately_fd1_1_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: #666666;
	}

	.payImmediately_fd1_1 {
		margin: 28rpx 0rpx 0rpx 0rpx;
	}

	.payImmediately_price2_fd1_0_c1 {
		font-size: 56rpx;
	}

	.payImmediately_price1_fd1_0_c1 {
		font-size: 64rpx;
	}

	.payImmediately_fd1_0_c1 {
		color: #FA2033;
		font-weight: 700;
	}

	.payImmediately_fd1_0_c0 {
		font-size: 48rpx;
		font-weight: 700;
		color: #FA2033;
		line-height: 48rpx;
	}

	.payImmediately_flex_2 {
		background: #fff;
		background-size: #eee;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.payImmediately_fd2_1_c1_c2 {
		width: 36rpx;
		height: 36rpx;
	}

	.payImmediately_fd2_1_c1_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
		margin: 0rpx 24rpx 0rpx 24rpx;
	}

	.payImmediately_fd2_1_c1_c0 {
		width: 56rpx;
		height: 56rpx;
	}

	.payImmediately_fd2_1_c1 {
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.payImmediately_fd2_1_c0_c2 {
		width: 36rpx;
		height: 36rpx;
	}

	.payImmediately_fd2_1_c0_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
		margin: 0rpx 24rpx 0rpx 24rpx;
	}

	.payImmediately_fd2_1_c0_c0 {
		width: 56rpx;
		height: 56rpx;
	}

	.payImmediately_fd2_1_c0 {
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.payImmediately_fd2_0_c0 {
		font-weight: 700;
		font-size: 28rpx;
		color: #2A2A2A;
		line-height: 40rpx;
	}

	.payImmediately_fd2_0 {
		border-bottom: 1px solid #eee;
		line-height: 45rpx;
		margin: 0rpx 0rpx 8rpx 0rpx;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.payImmediately_flex_3 {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(40rpx + var(--window-bottom));
	}

	.payImmediately_fd3_0 {
		background: rgba(48, 131, 255, 1);
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
		font-weight: 500;
	}
</style>